import csv
import numpy as np
from scipy import stats

def build_data_list(inputCSV):
    sKey = []
    fn = inputCSV
    ra = csv.DictReader(file(fn), dialect="excel")
    
    for record in ra:
        #print record[ra.fieldnames[0]], type(record[ra.fieldnames[-1]])
        for item in ra.fieldnames:
            temp = float(record[item])
            sKey.append(temp)
    sKey = np.array(sKey)
    sKey.shape=(-1,len(ra.fieldnames))
    return sKey


#--------------------------------------------------------------------------
#MAIN

if __name__ == "__main__":
    inputCSV = 'D:/My Documents/My Dropbox/GEOG 731/final project/inoutflow.csv'
    data = build_data_list(inputCSV)
    x = data[:,1]
    y = data[:,2]
    gradient, intercept, r_value, p_value, std_err = stats.linregress(x,y)
    print "Gradient and intercept", gradient, intercept
    print "R-squared", r_value**2
    print "p-value", p_value
    